// api/register.ts
import apiClient from './index';

// 教师注册参数类型
export interface TeacherRegisterParams {
  username: string;
  password: string;
  teacher_password: string;
}

// 教师注册响应类型
export interface TeacherRegisterResponse {
  code: number;
  content: {
    name: string;
    role: string;
    user_id: number;
    username: string;
  };
  msg: string;
}

// 教师创建学生账号参数
export interface CreateStudentParams {
  student_id: number;
  name: string;
  class_id: number;
  teacher_password: string;
}

// 教师创建学生账号响应
export interface CreateStudentResponse {
  code: number;
  content: {
    class_id: number;
    password: string;
    student_id: string;
    user_id: number;
    username: string;
  };
  msg: string;
}

/**
 * 教师注册账号
 */
export const registerTeacher = async (
  params: TeacherRegisterParams
): Promise<TeacherRegisterResponse> => {
  const response = await apiClient.post<TeacherRegisterResponse>(
    '/register/teacher-account',
    params
  );
  return response.data;
};

/**
 * 教师创建学生账号
 */
export const createStudentAccount = async (
  params: CreateStudentParams
): Promise<CreateStudentResponse> => {
  const response = await apiClient.post<CreateStudentResponse>(
    '/register/student',
    params
  );
  return response.data;
};

// 创建教师参数
export interface CreateTeacherParams {
  name: string;
  position: string;
  admin_password: string;
}

// 创建教师响应类型
export interface CreateTeacherResponse {
  code: number;
  content: {
    password_hash: string;
    teacher_id: number;
    user_id: number;
  };
  msg: string;
}

/**
 * 创建教师账号
 */
export const createTeacher = async (
  params: CreateTeacherParams
): Promise<CreateTeacherResponse> => {
  const response = await apiClient.post<CreateTeacherResponse>('/register/teacher', params);
  return response.data;
};